        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>MathBox class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="MathBox">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/MathBox.html">MathBox</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>MathBox</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class MathBox {
 static const double TWO_PI = math.PI * 2.0;

 MathBox();

 /**
  * Given a value within the range specified by [fromMin] and [fromMax],
  * returns a value with the same relative position in the range specified
  * from [toMin] and [toMax]. For example, given a [val] of 2 in the
  * "from range" of 0-4, and a "to range" of 10-20, would return 15.
  */
 static num translateAndScale(num val, num fromMin, num fromMax, num toMin,
     num toMax) {
   final num mult = (val - fromMin) / (fromMax - fromMin);
   final num res = toMin + mult * (toMax - toMin);
   return res;
 }

 /** Solve [matrix]x = [b] without calculating the inverse of [matrix].
  *  [matrix] must be a 3x3 matrix and [b] must be a vec3. */
 static vec3 solve33(mat3 matrix, vec3 b) {
   vec3 out = cross(matrix.col1, matrix.col2);
   num det = dot(matrix.col0, out);
   if (det != 0.0) det = 1.0 / det;

   out = cross(matrix.col1, matrix.col2);
   num x = det * dot(b, out);
   out = cross(b, matrix.col2);
   num y = det * dot(matrix.col0, out);
   out = cross(matrix.col1, b);
   num z = det * dot(matrix.col0, out);
   out.setComponents(x, y, z);
   return out;
 }

 /** Solve [matrix]x = [b] without calculating the inverse of [matrix].
  *  [matrix] must be a 2x2 or 3x3 matrix, and in the latter case the top-left
  *  2x2 elements will be used. [b] must be a vec2. */
 static vec2 solve22(dynamic matrix, vec2 b) {
   assert(matrix is mat2 || matrix is mat3);
   num a11 = matrix.col0.x, a12 = matrix.col1.x,
       a21 = matrix.col0.y, a22 = matrix.col1.y;
   num det = a11 * a22 - a12 * a21;
   if (det != 0.0) det = 1.0 / det;
   final vec2 out = new vec2(a22 * b.x - a12 * b.y, a11 * b.y - a21 * b.x);
   out.scale(det);
   return out;
 }
}
</pre>
</div>
<div>
<h3>Static Properties</h3>
<div class="field"><h4 id="TWO_PI">
<button class="show-code">Code</button>
const double         <strong>TWO_PI</strong> <a class="anchor-link"
            href="#TWO_PI"
            title="Permalink to MathBox.TWO_PI">#</a>
        </h4>
        <div class="doc">
<pre class="source">
TWO_PI = math.PI * 2.0
</pre>
</div>
</div>
</div>
<div>
<h3>Static Methods</h3>
<div class="method"><h4 id="translateAndScale">
<button class="show-code">Code</button>
num <strong>translateAndScale</strong>(num val, num fromMin, num fromMax, num toMin, num toMax) <a class="anchor-link" href="#translateAndScale"
              title="Permalink to MathBox.translateAndScale">#</a></h4>
<div class="doc">
<p>Given a value within the range specified by 
<span class="param">fromMin</span> and 
<span class="param">fromMax</span>,
returns a value with the same relative position in the range specified
from 
<span class="param">toMin</span> and 
<span class="param">toMax</span>. For example, given a 
<span class="param">val</span> of 2 in the
"from range" of 0-4, and a "to range" of 10-20, would return 15.</p>
<pre class="source">
static num translateAndScale(num val, num fromMin, num fromMax, num toMin,
   num toMax) {
 final num mult = (val - fromMin) / (fromMax - fromMin);
 final num res = toMin + mult * (toMax - toMin);
 return res;
}
</pre>
</div>
</div>
<div class="method"><h4 id="solve33">
<button class="show-code">Code</button>
<a href="../vector_math/vec3.html">vec3</a> <strong>solve33</strong>(<a href="../vector_math/mat3.html">mat3</a> matrix, <a href="../vector_math/vec3.html">vec3</a> b) <a class="anchor-link" href="#solve33"
              title="Permalink to MathBox.solve33">#</a></h4>
<div class="doc">
<p>Solve 
<span class="param">matrix</span>x = 
<span class="param">b</span> without calculating the inverse of 
<span class="param">matrix</span>.
 
<span class="param">matrix</span> must be a 3x3 matrix and 
<span class="param">b</span> must be a vec3. </p>
<pre class="source">
static vec3 solve33(mat3 matrix, vec3 b) {
 vec3 out = cross(matrix.col1, matrix.col2);
 num det = dot(matrix.col0, out);
 if (det != 0.0) det = 1.0 / det;

 out = cross(matrix.col1, matrix.col2);
 num x = det * dot(b, out);
 out = cross(b, matrix.col2);
 num y = det * dot(matrix.col0, out);
 out = cross(matrix.col1, b);
 num z = det * dot(matrix.col0, out);
 out.setComponents(x, y, z);
 return out;
}
</pre>
</div>
</div>
<div class="method"><h4 id="solve22">
<button class="show-code">Code</button>
<a href="../vector_math/vec2.html">vec2</a> <strong>solve22</strong>(matrix, <a href="../vector_math/vec2.html">vec2</a> b) <a class="anchor-link" href="#solve22"
              title="Permalink to MathBox.solve22">#</a></h4>
<div class="doc">
<p>Solve 
<span class="param">matrix</span>x = 
<span class="param">b</span> without calculating the inverse of 
<span class="param">matrix</span>.
 
<span class="param">matrix</span> must be a 2x2 or 3x3 matrix, and in the latter case the top-left
 2x2 elements will be used. 
<span class="param">b</span> must be a vec2. </p>
<pre class="source">
static vec2 solve22(dynamic matrix, vec2 b) {
 assert(matrix is mat2 || matrix is mat3);
 num a11 = matrix.col0.x, a12 = matrix.col1.x,
     a21 = matrix.col0.y, a22 = matrix.col1.y;
 num det = a11 * a22 - a12 * a21;
 if (det != 0.0) det = 1.0 / det;
 final vec2 out = new vec2(a22 * b.x - a12 * b.y, a11 * b.y - a21 * b.x);
 out.scale(det);
 return out;
}
</pre>
</div>
</div>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="MathBox">
<button class="show-code">Code</button>
new <strong>MathBox</strong>() <a class="anchor-link" href="#MathBox"
              title="Permalink to MathBox.MathBox">#</a></h4>
<div class="doc">
<pre class="source">
MathBox();
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
